const fs = require('fs');
const path = require('path');

// 确保目标目录存在
const targetDir = path.join(__dirname, 'dist', 'migrations');
if (!fs.existsSync(targetDir)) {
  fs.mkdirSync(targetDir, { recursive: true });
  console.log(`Created directory: ${targetDir}`);
}

// 源目录
const sourceDir = path.join(__dirname, 'src', 'migrations');
if (!fs.existsSync(sourceDir)) {
  console.log(`Source directory does not exist: ${sourceDir}`);
  process.exit(0);
}

// 复制所有SQL文件
try {
  const files = fs.readdirSync(sourceDir)
    .filter(file => file.endsWith('.sql'));
  
  if (files.length === 0) {
    console.log('No SQL files found to copy');
    process.exit(0);
  }
  
  files.forEach(file => {
    const sourcePath = path.join(sourceDir, file);
    const targetPath = path.join(targetDir, file);
    
    fs.copyFileSync(sourcePath, targetPath);
    console.log(`Copied: ${file}`);
  });
  
  console.log(`Successfully copied ${files.length} migration files`);
} catch (error) {
  console.error(`Error copying files: ${error.message}`);
  process.exit(1);
} 